package activity.personal.qianbao;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;


import com.itboye.hutoubenjg.R;

import java.util.Observable;
import java.util.Observer;

import base.BaseActivity;
import base.MyApplcation;
import bean.personal_bean.MoneyShengyuBean;
import presenter.SysTemPresenter;
import util.EdiTextPut;
import util.utls.ByAlert;
import util.utls.Const;
import util.utls.IsUtilUid;
import util.utls.SPUtils;
import util.volley.ResultEntity;

/**
 * 提现到支付宝
 */
public class TiXianToZhiFuBaoActivity extends BaseActivity implements Observer {
    TextView tvTitle;
    ImageView back;
    private TextView tixian02_num;//提现账号
    private EditText tixian02_money;//提现余额
    private TextView tixian02_yue;//剩余
    private TextView tixian_ok;//确定
    private String zhanghao, yue, shengyu;
    SysTemPresenter presenter;
    MoneyShengyuBean bean;
    String choose;
    String qian;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ti_xian_to_zhi_fu_bao);
        tvTitle.setText("提现申请");
        presenter = new SysTemPresenter(this);
        bean = new MoneyShengyuBean();
        Log.d("byaltitle", "yue");
         qian = (String) SPUtils.get(MyApplcation.ctx, null, Const.QIAN, "");

        double dbqian=Double.parseDouble(qian);
        tixian02_yue.setText(""+dbqian/100+"元");
        tixian_ok = (TextView) findViewById(R.id.tixian_ok);

        EdiTextPut.setPricePoint(tixian02_money);

    }

    @Override
    protected void onInit() {

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tixian_ok:
                zhanghao = tixian02_num.getText().toString().trim();
                String s =  EdiTextPut.getPrice();
                if (s.equals("")) {
                    ByAlert.alert("请填写具体金额");
                } else if (choose == null || choose.equals("")) {
                    Intent intent = new Intent(TiXianToZhiFuBaoActivity.this, ActivityZhuang.class);
                    startActivityForResult(intent, 101);

                } else {
                    if(qian.equals("0")||Double.parseDouble(qian)<Double.parseDouble(s)){
                        ByAlert.alert("余额不足");
                    }else {
                        showProgressDialog("请稍后...",true);
                        presenter.onTixian(IsUtilUid.isUid(), Double.parseDouble(s)*100+"", choose);

                    }
                }

                break;
            case R.id.tixian02_num:
                Intent intent = new Intent(TiXianToZhiFuBaoActivity.this, ActivityZhuang.class);
                startActivityForResult(intent, 101);

                break;
            case R.id.back:
                finish();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 101 && resultCode == 102) {
           String  name = data.getStringExtra("choose");
            choose=data.getStringExtra("acctivty");
            tixian02_num.setText("请选择账户:" + name);

        }
    }

    @Override
    public void update(Observable observable, Object data) {
        ResultEntity entity = handlerError(data);
        if (entity != null) {
            IsUtilUid.tianjia(entity);
            if (entity.getEventType() == presenter.TIxian_success) {
                ByAlert.alert(entity.getData());
                Log.d("byaltitles", entity.getData()+"");
                finish();

            }
        }
        try {
            closeProgressDialog();
        } catch (Exception e) {
        }
    }

}
